//
//  LFOpinionView.m
//  商互通
//
//  Created by 王林峰 on 16/5/2.
//  Copyright © 2016年 sdy. All rights reserved.
//

#import "LFOpinionView.h"
@interface LFOpinionView()<UITextViewDelegate>
@property (nonatomic, weak)UILabel *placeholderLable;
@end
@implementation LFOpinionView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.font = [UIFont systemFontOfSize:14];
        
        //添加占位文字的label
        UILabel *placeholderLable = [[UILabel alloc] init];
      //  placeholderLable.textColor = [UIColor whiteColor];
        placeholderLable.font = [UIFont systemFontOfSize:15.0];
        placeholderLable.textColor = RGB(189, 189, 193);
        placeholderLable.font = self.font;
        placeholderLable.numberOfLines = 0;
        [self addSubview:placeholderLable];
        self.placeholderLable = placeholderLable;
          [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange) name:UITextViewTextDidChangeNotification object:self];
    }
    return self;
}
- (void)textDidChange{
    self.placeholderLable.hidden = self.text.length;
    
    
    
}
//移除通知
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    
    //设置占位文字的位置
    self.placeholderLable.x = 5;
    self.placeholderLable.y = 8;
    
    //设置大小
    self.placeholderLable.size = [self.placeholderLable.text sizeWithFont:self.placeholderLable.font constrainedToSize:CGSizeMake(self.width - 10, MAXFLOAT)];
}

- (void)setPlaceholder:(NSString *)placeholder{
    _placeholder = placeholder;
    //设置文字
    self.placeholderLable.text = placeholder;
}

- (void)setFont:(UIFont *)font{
    [super setFont:font];
    
    
    //去调整placeholder的字体大小
    self.placeholderLable.font = font;
}







@end
